{extend name="adminblue/base" /}
{block name="resources"/}
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>
<style>
.right-indent:after{
	content:'';
	display:inline-block;
	width:40%;
}
#order_no, #add-btn {
    float: left;
    margin-right: 20px !important;
}
#logistics-box .input-common {
    display: block !important;
    width: 100% !important;
}
.set-style dl dt {
    width: auto !important;
    text-align: left;
    margin-bottom: 10px;
}
.set-style .btn-box {
    margin-top: 10px;
}
.remove-btn {
    color: red;
}
</style>
{/block}
{block name="main"}
<div class="ns-main">
    <div class="space-10"></div>
    <div class="set-style">
        <form id="logistics-form">
            <dl>
                <dt>订单外部编号：</dt>
                <dd>
                    <input type="text" id="order_no" name="order_no" value="{$orderNo}" maxlength="30" class="input-common">
                    <button type="button" id="add-btn" class="btn-common btn-big">添加</button>
                </dd>
            </dl>
            <table class="table-class">
                <colgroup>
                        <col style="width: 15%;">
                        <col style="width: 60%;">
                        <col style="width: 10%;">
                        <col style="width: 10%;">
                </colgroup>
                <thead>
                        <tr>
                                <th align="center">操作时间</th>
                                <th align="center">操作信息</th>
                                <th align="center">操作人</th>
                                <th align="center">操作</th>
                        </tr>
                </thead>
                <tbody id="logistics-box"></tbody>
            </table>
            <dl class="btn-box">
                <dt>
                    <button type="button" class="btn-common btn-big" id="sub-btn">保存</button>
                    <button type="button" class="btn-common-cancle btn-big" onclick="window.location.href = window.history.go(-1);">返回</button>
                </dt>
            </dl>
        </form>
    </div>
</div>
<div class="model-box" style="display: none;">
    <table id="table-model">
        <tbody>
            <tr class="line">
                <td>
                    <input class="input-medium input-common harf" type="text" name="time[]" onclick="WdatePicker({skin:'twoer',dateFmt:'yyyy-MM-dd HH:mm:ss'})">
                </td>
                <td><input type="text" name="info[]" class="input-common"/></td>
                <td><input type="text" name="username[]" class="input-common"/></td>
                <td align="center"><span class="remove-btn">删除</span></td>
            </tr>
            <tr class="no-data">
                <td align="center" colspan="4"><i>暂无数据</i></td>
            </tr>
        </tbody>
    </table>
</div>
{/block}
{block name="script"}
<script type="text/javascript">

    var content = {$content};

    if (content.length == 0)
    {
        $('#table-model tr.no-data').clone().appendTo($('#logistics-box'));
    }
    else
    {
        for(var i in content)
        {
            var lineData = content[i];
            
            var lineDome = $('#table-model tr.line').clone();
            
            lineDome.find('[name="time[]"]').val(lineData['time']);
            
            lineDome.find('[name="info[]"]').val(lineData['info']);
            
            lineDome.find('[name="username[]"]').val(lineData['username']);
            
            lineDome.appendTo($('#logistics-box'));
        }
    }

$('#add-btn').click(function()
{
    var dataNum = $('#logistics-box').find('.no-data').length;

    if ( dataNum > 0 )
    {
        $('#logistics-box').find('.no-data').remove();
    }
    $('#table-model tr.line').clone().appendTo($('#logistics-box'));
});

$('#logistics-box').on('click', '.remove-btn', function()
{
    $(this).parent().parent().remove();
    
    var lineNum = $('#logistics-box').find('.line').length;
    
    if ( lineNum == 0 )
    {
        $('#table-model tr.no-data').clone().appendTo($('#logistics-box'));
    }
});

$('#sub-btn').click(function(){
    var data = $('#logistics-form').serialize();
    
    var url = "{:__URL('ADMIN_MAIN/Order/logisticsEdit')}";
    
    $.post(url, data, function(rs)
    {
        alert(rs.message);
        
        if ( rs.status == 1 )
        {
            console.log('刷新');
        }
        
    }, 'json');
});

////加载数据
//function LoadingInfo(page_index) {
//	$.ajax({
//		type : "post",
//		url : "{:__URL('ADMIN_MAIN/Order/invoiceList')}",
//		data : {
//			"page_index" : page_index,
//			"page_size" : $("#showNumber").val(),
//			"start_date" : $("#startDate").val(),
//			"end_date" : $("#endDate").val(),
//			"order_no" : $("#order_no").val()
//		},
//		success : function(data) {
//			if (data["data"].length > 0) {
//				$(".table-class tbody").empty();
//				for (var i = 0; i < data["data"].length; i++) {
//					var html = '';
//					html += '<tr align="center">';
//						html += '<td><i class="checkbox-common"><input type="checkbox" value="'+ data["data"][i]["order_id"] +'"></i></td>';
//						html += '<td align="left"><a href="'+__URL('ADMIN_MAIN/order/orderdetail?order_id=' + data["data"][i]["order_id"] )+'">' + data["data"][i]["order_no"] + '</a></td>';
//						html += '<td align="left">' + data["data"][i]["user_name"] + '</td>';
//						html += '<td align="right" class="right-indent">' + data["data"][i]["pay_money"] + '</td>';
//						html += '<td align="left">' + data["data"][i]["invoice"][0] + '</td>';
//						html += '<td align="left">' + data["data"][i]["invoice"][1] + '</td>';
//						html += '<td align="left">' + data["data"][i]["invoice"][2] + '</td>';
//						
//						html += '<td >' + timeStampTurnTime(data["data"][i]["create_time"]) + '</td>';
//						html += '<td>';
//							//html += '<a href="###">查看</a>';
//						html += '</td>';
//					html += '</tr>';
//					$(".table-class tbody").append(html);
//				}
//			} else {
//				var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
//				$(".table-class tbody").html(html);
//			}
//			initPageData(data["page_count"],data['data'].length,data['total_count']);
//			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
//		}
//	});
//}


</script>
{/block}